﻿using System.ComponentModel;

namespace uTrade.ViewModels
{
    public class ChartViewModel : INotifyPropertyChanged
    {
        private string _symbol;
        private string _name;
        private double _change;
        private double _changeP;
        private double _lastHigh;
        private double _lastLow;
        private double _lastOpen;
        private double _lastClose;
        private double _lastVolume;
        private double _dayChange;
        private double _dayTend;

        public ChartViewModel()
        {
        }

        public string Symbol
        {
            get
            {
                return _symbol;
            }
            set
            {
                _symbol = value;
                RaisePropertyChanged("Symbol");
            }
        }

        public string Name
        {
            get
            {
                return _name;
            }
            set
            {
                _name = value;
                RaisePropertyChanged("Name");
            }
        }

        public double Change
        {
            get
            {
                return _change;
            }
            set
            {
                _change = value;
                RaisePropertyChanged("Change");
            }
        }

        public double ChangePercent
        {
            get
            {
                return _changeP;
            }
            set
            {
                _changeP = value;
                RaisePropertyChanged("ChangePercent");
            }
        }

        public double High
        {
            get
            {
                return _lastHigh;
            }
            set
            {
                _lastHigh = value;
                RaisePropertyChanged("High");
            }
        }

        public double Low
        {
            get
            {
                return _lastLow;
            }
            set
            {
                _lastLow = value;
                RaisePropertyChanged("Low");
            }
        }

        public double Open
        {
            get
            {
                return _lastOpen;
            }
            set
            {
                _lastOpen = value;
                Change = _lastClose - _lastOpen;
                ChangePercent = Change / _lastOpen;
                RaisePropertyChanged("Open");
            }
        }

        public double Close
        {
            get
            {
                return _lastClose;
            }
            set
            {
                _lastClose = value;
                RaisePropertyChanged("Close");
            }
        }

        public double Volume
        {
            get
            {
                return _lastVolume;
            }
            set
            {
                _lastVolume = value;
                RaisePropertyChanged("Volume");
            }
        }

        #region INotifyPropertyChanged属性

        public event PropertyChangedEventHandler PropertyChanged;

        #endregion INotifyPropertyChanged属性

        #region 属性更改方法

        private void RaisePropertyChanged(string propertyName)
        {
            PropertyChangedEventHandler handler = PropertyChanged;
            if (handler != null)
            {
                handler(this, new PropertyChangedEventArgs(propertyName));
            }
        }

        #endregion 属性更改方法
    }
}